package org.bugjail.dataaccess.jdbc.objects;

import java.sql.PreparedStatement;
import java.util.List;

import org.bugjail.data.History;
import org.bugjail.dataaccess.jdbc.connection.QueryException;
import org.bugjail.dataaccess.jdbc.connection.QueryManager;
import org.bugjail.dataaccess.objects.HistoryDAO;

class JDBCHistoryDAO implements HistoryDAO {

	private final String PROPERTIES_FILE = "/org/bugjail/dataaccess/jdbc/properties/historydao.properties";
	
	private final String PROPERTY_INSERT = "insert";
	
	@Override
	public void create(History element) {
		QueryManager queryManager = null;
		try {
			try {
				queryManager = new QueryManager(PROPERTIES_FILE);
				PreparedStatement statement = queryManager
				.getPreparedStatement(PROPERTY_INSERT);
				statement.setInt(1, element.getTestDesign().getId());
				statement.setInt(2, element.getAuthor().getId());
				statement.setString(3, element.getVersion());
				statement.executeUpdate();
				
				QueryManager.commit(queryManager);
			} finally {
				QueryManager.close(queryManager);
			}
		} catch (Exception e) {
			QueryManager.rollback(queryManager);
			throw new QueryException(e.getMessage());
		}
	}

	@Override
	public void delete(History element) {
		// TODO Auto-generated method stub

	}

	@Override
	public List<History> retrieveAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public History retrieveById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<History> retrieveByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void update(History element) {
		// TODO Auto-generated method stub

	}

}
